package com.tlxch.controller.student;

import com.tlxch.pojo.SHabit;
import com.tlxch.result.Result;
import com.tlxch.server.student.StuSHabitService;
import com.tlxch.utils.TextSpecialWordChecker;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "学习习惯相关接口")
@Slf4j
@RestController
@RequestMapping("/student/habit")
public class StuSHabitController {
    @Autowired
    StuSHabitService stuSHabitService ;

    @PostMapping("/shabit")
    @ApiOperation("添加学习习惯")
    public Result addStuSHabit(@RequestBody SHabit sHabit){
        int i = TextSpecialWordChecker.checkText(sHabit.getShHcontent());
        int i1 = TextSpecialWordChecker.checkText(sHabit.getShFrequency());
        int i2 = TextSpecialWordChecker.checkText(sHabit.getShDuration());
        if(i == 0 || i1 == 0 || i2 == 0){
            return Result.error("含有非法字符");
        }
        stuSHabitService.addStuSHabit(sHabit);
        return Result.success();
    }

    @GetMapping
    @ApiOperation("查看学习习惯记录")
    public Result<List<SHabit>> getStuSHabit(String sSid){
        List<SHabit> sHabits = stuSHabitService.getBySid(sSid);
        return Result.success(sHabits);
    }
}
